"""
@File    ：ui_test_demo.py
@Author  ：ixiaodu
@Date    ：2024/4/26
@Desc    ：
"""
import os
# 导包
from time import sleep
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.wait import WebDriverWait

from utils.get_browser_driver import determine_google_drive

# 实例化浏览器
driver = webdriver.Chrome(service=Service(determine_google_drive()))

# 打开网址
driver.get('http://192.168.1.47/')
# 最大化浏览器
driver.maximize_window()

# 进行登录操作
driver.find_element(By.CSS_SELECTOR, ".el-form-item:nth-child(1) .el-input__inner").send_keys('ceshi1')
driver.find_element(By.XPATH, "//input[@type='password']").send_keys('123456')
driver.find_element(By.CSS_SELECTOR, ".el-button").click()
sleep(6)

driver.find_element(By.XPATH, "/html//div[@id='app']/div/div[1]//ul[@role='menubar']/div[5]/li[@role='menuitem']/div[@class='el-submenu__title']").click()
sleep(1)
driver.find_element(By.XPATH, "/html//div[@id='app']/div//ul[@role='menubar']/div[5]/li[@role='menuitem']/ul[@role='menu']/div[1]/li[@role='menuitem']/div[@class='el-submenu__title']").click()
sleep(1)
driver.find_element(By.CSS_SELECTOR, ".el-menu:nth-child(1) > .menu-wrapper:nth-of-type(5) .nest-menu:nth-of-type(1) .nest-menu:nth-of-type(1) .el-menu-item").click()
sleep(5)

ele = WebDriverWait(driver,10,0.5).until(EC.presence_of_element_located((By.XPATH, "//div[@class='el-table__fixed-body-wrapper']/table/tbody/tr[1]/td[13]//button/span[.='更多菜单']")))

# 实例化鼠标
action = ActionChains(driver)
# 鼠标悬停
action.move_to_element(ele)
# 鼠标执行
action.perform()

sleep(1)
driver.find_element(By.CSS_SELECTOR, "[x-placement] .el-dropdown-menu__item:nth-of-type(3)").click()
sleep(1)
driver.find_element(By.CSS_SELECTOR, ".repair-user").click()
sleep(1)
driver.find_element(By.XPATH, "//body/div[@class='el-dialog__wrapper']/div[@role='dialog']//div[@class='dialog-footer']/button[2]/span[.='确定']").click()
sleep(1)

text = WebDriverWait(driver,10,0.5).until(EC.presence_of_element_located((By.XPATH, "/html//div[@role='alert']//h2[@class='el-notification__title']")))
print(text.text)

# 时间轴看效果
sleep(5)

# 关闭页面
driver.quit()
